package com.chengqs.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

@Component
public class EmailUtil {
    @Autowired
    private JavaMailSender javaMailSender;

    public void send(String loginEmail,String randomCode){
        //1. 创建一个封装邮箱信息的对象
        SimpleMailMessage msg = new SimpleMailMessage();
        //email-info
        msg.setFrom("476141726@qq.com");//发送方邮箱需要和application-dev.yml中配置的邮箱保持一致
        msg.setSubject("常工院登录验证码");//邮箱的主题
        msg.setText(randomCode);
        msg.setTo(loginEmail);//邮箱的接收方
        //end - 发送邮箱
        javaMailSender.send(msg);
    }
}
